PLAT 06 - C Open File Limit
Title Banner


Technical Q&A's


PLAT 06 - C Open File Limit (1-June-95)


Q Our development group has encountered a problem with their Macintosh port (they are developing for the 68K only, under MPW 3.3.1 with the MPW C 3.2.4 compiler). They allocate a large number of FILE streams via fopen(), and eventually, the fopen() calls begin to fail. We believe that they have encountered MPW's limit of 20 open files.

Microsoft has provided a standard C library that has a larger static FILE stream buffer to circumvent this problem, and they would like get a similar MPW C library from Apple.

A The _NFILES macro in stdio.h defines the maximum number of files that can be opened. This is set to 40 in the ETO #16 pre-release, SC-compatible, MPW libraries (otherwise it's 20). Support for more than 40 files is not planned, so there won't be a final version of libraries for MPW C with a larger open-file limit.

There is a possible workaround -- use our low-level I/O calls instead of the stream I/O calls. The number of files you can open with low-level calls is limited only by available memory. (These calls are documented in the chapter on building MPW tools in Building and Managing Programs with MPW). Low-level I/O calls can be used in applications, but this isn't obvious because the documentation isn't well organized.

It's possible that our low-level I/O calls may not provide you with sufficient functionality for your port, assuming that you are using fprintf or a related function, and there is no low-level equivalent for this. If your usage is limited to getc/putc/fread/fwrite, it would be fairly simple to emulate these on top of low-level I/O using the low-level read and write functions. However, a better, long-term solution would be to move to the SC compiler and its associated libraries.

Technical Support
Technical Q&As
Previous Question | Contents | Next Question

Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help